import {ActionName, CropType, FlowerName, type FlowerTips, FruitName, type GardenFlowerType,} from "@/components/type";
import {IconType} from "@/components/IconFont/type";
import Action from "@/modal/Action";
import Score from "@/modal/Score";
import {reactive} from "vue";
import {ScoreType} from "@/components/ScorePanel/type";
import Goods from "@/modal/Goods";
import Compost from "@/modal/Compost";
import Buff from "@/modal/Buff";
import {store} from "@/modal/store";

const score = reactive(Score.getInstance());
const goods = reactive(Goods.getInstance());
const action = reactive(Action.getInstance());
const compost = reactive(Compost.getInstance());
const buff = reactive(Buff.getInstance());
export default class Flower {
  readonly type = CropType.FLOWER;
  readonly name: FlowerName;
  readonly chineseName: FlowerName;
  readonly ripeStage: number = 6;
  private currentStage_: number = 0;
  readonly showTips: FlowerTips[] | any;

  constructor(options?: GardenFlowerType) {
    this.name = options?.name!;
    this.chineseName = options?.chineseName!;
  }

  // 是否成熟
  get isRipen() {return this.currentStage_ === this.ripeStage;}

  // 成熟点位
  get awardStep(): boolean {return false;}

  get currentStep() {return this.currentStage_;}

  growUp(): Flower {
    if (!this.isRipen) {
      this.currentStage_++;
    }
    return this;
  }

  getAward() {return this;}

}

// 郁金香
export class Tulip extends Flower {
  readonly name = FlowerName.TULIP;
  readonly chineseName = FlowerName.CHINESE_TULIP;
  private score_: number = 0;
  readonly showTips: FlowerTips[] | any = [
    {
      isInsideIcon: true, insideIconType: IconType.BONUS, slotDesc: true,
      slot: {icon: {type: IconType.FRUIT}}
    },
    {
      isInsideIcon: false, slotDesc: true,
      slot: {
        icon: {type: IconType.GOODS, number: 2, descIn: `←`},
        descIcon: {type: IconType.PEACH},
      }
    }, {},
    {
      isInsideIcon: false, slotDesc: true,
      slot: {
        icon: {type: IconType.GOODS, number: 3, descIn: `←`},
        descIcon: {type: IconType.PEACH},
      }
    }, {},
    {
      isInsideIcon: false, slotDesc: true,
      slot: {
        icon: {type: IconType.SCORE, number: 1, descIn: "←"},
        descIcon: {type: IconType.FRUIT, number: 1, descIn: "(最多15)"}
      }
    }
  ];

  override get awardStep() {return this.currentStep !== 3 && this.currentStep !== 5;}

  getAward() {
    if (this.awardStep) {
      switch (this.currentStep) {
        case 1:
          action.setAction([ActionName.FRUIT]);
          break;
        case 2:
          buff.extraGoodsForPeach(2, IconType.FLOWER);
          break;
        case 4:
          buff.extraGoodsForPeach(1, IconType.FLOWER);
          break;
        default:
          buff.extraScoreForFruitNum(1);
          break;
      }
    }
    return this;
  }

  get score() {return this.score_;}

}

// 绣球花
export class Hydrangea extends Flower {
  readonly name = FlowerName.HYDRANGEA;
  readonly chineseName = FlowerName.CHINESE_HYDRANGEA;
  private score_: number = 7;
  readonly showTips: FlowerTips[] | any = [
    {isInsideIcon: true, insideIconType: IconType.BONUS, slotDesc: true, slot: {icon: {type: IconType.APPLE}}}, {},
    {isInsideIcon: true, insideIconType: IconType.BONUS, slotDesc: true, slot: {icon: {type: IconType.BLACKBERRY}}},
    {isInsideIcon: true, insideIconType: IconType.BONUS, slotDesc: true, slot: {icon: {type: IconType.RASPBERRY}}},
    {isInsideIcon: true, insideIconType: IconType.BONUS, slotDesc: true, slot: {icon: {type: IconType.PEACH}}},
    {isInsideIcon: false, slotDesc: true, slot: {icon: {type: IconType.SCORE, number: 7}}}
  ];

  override get awardStep() {return this.currentStep !== 2;}

  getAward() {
    if (this.awardStep) {
      if (this.currentStep !== 6) {
        store.fruits.forEach(items => {
          switch (this.currentStep) {
            case 1:
              if (items.name === FruitName.APPLE) items.growUp().getAward();
              break;
            case 3:
              if (items.name === FruitName.BLACKBERRY) items.growUp().getAward();
              break;
            case 4:
              if (items.name === FruitName.RASPBERRY) items.growUp().getAward();
              break;
            case 5:
              if (items.name === FruitName.PEACH) items.growUp().getAward();
              break;
          }
        });
      } else {
        score.addScore(this.score, ScoreType.FLOWER);
      }
    }
    return this;
  }

  get score() {return this.score_;}
}

// 鸢尾花
export class Iris extends Flower {
  readonly name = FlowerName.IRIS;
  readonly chineseName = FlowerName.CHINESE_IRIS;
  private score_: number = 12;
  readonly showTips: FlowerTips[] | any = [
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.COMPOST, number: 1}}
    },
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.FARM, descIn: '区域+|-1'}}
    }, {},
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.FARM, descIn: '区域+|-2'}}
    }, {},
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.SCORE, number: 12}}
    }
  ];

  override get awardStep() {return this.currentStep !== 3 && this.currentStep !== 5;}

  getAward() {
    if (this.awardStep) {
      if (this.currentStep == 6) score.addScore(this.score, ScoreType.FLOWER);
      else if (this.currentStep == 1) compost.collectCompost(1);
      else buff.rangeCompostForReclaim(1);
    }
    return this;
  }

  get score() {return this.score_;}
}

// 风信子
export class Hyacinth extends Flower {
  readonly name = FlowerName.HYACINTH;
  readonly chineseName = FlowerName.CHINESE_HYACINTH;
  private score_: number = 10;
  readonly showTips: FlowerTips[] | any = [
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.GOODS, number: 2}}
    },
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.GOODS, number: 2}}
    }, {},
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.GOODS, number: 2}}
    }, {},
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.SCORE, number: 10}}
    }
  ];

  override get awardStep() {return this.currentStep !== 3 && this.currentStep !== 5;}

  getAward() {
    if (this.awardStep) {
      if (this.currentStep === 6) score.addScore(this.score, ScoreType.FLOWER);
      else goods.gainGoods(2);
    }
    return this;
  }

  get score() {return this.score_;}
}

// 番红花
export class Saffron extends Flower {
  readonly name = FlowerName.SAFFRON;
  readonly chineseName = FlowerName.CHINESE_SAFFRON;
  private score_: number = 6;
  readonly showTips: FlowerTips[] | any = [
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.COMPOST, number: 2}}
    },
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.COMPOST, number: 1}}
    },
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.COMPOST, number: 1}}
    },
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.COMPOST, number: 2}}
    }, {},
    {
      isInsideIcon: false, slotDesc: true,
      slot: {icon: {type: IconType.SCORE, number: 6}}
    }
  ];

  override get awardStep() {return this.currentStep !== 5;}

  getAward() {
    if (this.awardStep) {
      if (this.currentStep === 6) score.addScore(this.score, ScoreType.FLOWER);
      else if (this.currentStep === 1 || this.currentStep === 4) compost.collectCompost(2);
      else compost.collectCompost(1);
    }
    return this;
  }

  get score() {return this.score_;}
}

// 黄水仙
export class Daffodil extends Flower {
  readonly name = FlowerName.DAFFODIL;
  readonly chineseName = FlowerName.CHINESE_DAFFODIL;
  private score_: number = 4;
  readonly showTips: FlowerTips[] | any = [
    {isInsideIcon: true, slotDesc: true, insideIconType: IconType.BONUS, slot: {icon: {type: IconType.TOOL}}}, {},
    {isInsideIcon: true, slotDesc: true, insideIconType: IconType.BONUS, slot: {icon: {type: IconType.TOOL}}},
    {isInsideIcon: true, slotDesc: true, insideIconType: IconType.BONUS, slot: {icon: {type: IconType.TOOL}}},
    {isInsideIcon: true, slotDesc: true, insideIconType: IconType.BONUS, slot: {icon: {type: IconType.TOOL}}},
    {isInsideIcon: false, slotDesc: true, slot: {icon: {type: IconType.SCORE, number: 4}}}
  ];

  override get awardStep() {return this.currentStep !== 2;}

  getAward() {
    if (this.awardStep) {
      if (this.currentStep !== 6) action.setAction([ActionName.TOOL]);
      else score.addScore(this.score, ScoreType.FLOWER);
    }
    return this;
  }

  get score() {return this.score_;}
}